package meatslope2.gameengine.gameobjects.model;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11Ext;

import meatslope2.application.SystemRegistry;
import meatslope2.gameengine.engine.Camera;

/**
 * Provides drawing method for game objects, as well as a cached texture name for opengl to bind to
 * @author Mitchell Thelen
 *
 */
public class Sprite 
{
	// ===========================================================
	// Members
	// ===========================================================
	
    // The OpenGL ES texture handle to draw.
    private int textureName;
    
    // The id of the original resource that mTextureName is based on.
    private int resourceId;
    
	// ===========================================================
	// Setters/Getters
	// ===========================================================
    
    public void setTextureName(int name) 
    { 
    	this.textureName = name;
    }

    public int getTextureName() 
    {
        return this.textureName;
    }

    public int getResourceId() 
    {
        return this.resourceId;
    }

	// ===========================================================
	// Constructors
	// ===========================================================
    
    public Sprite(int resourceId) 
    {
        this.resourceId = resourceId;
    }

	// ===========================================================
	// Methods
	// ===========================================================
    
    public final void draw(GL10 gl, DrawableGameObject gameObject) 
    {
    	Camera camera = SystemRegistry.camera;
    	
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);

        // Draw using the DrawTexture extension.
        ((GL11Ext) gl).glDrawTexfOES(gameObject.position.x - (gameObject.isCameraEnabled() ? camera.getPosition().x : 0), 
        		gameObject.position.y,
        		1, 
        		gameObject.width, 
        		gameObject.height);
    }
}
